<?php

class Sensor_DS18B20 implements Sensor_Sensor {
	private $id;
	
	public function __construct($id) {
		$this->id = $id;
	}

	public function getTemp() {
		$res = null;
		$url = sprintf("/sys/bus/w1/devices/%s/w1_slave", $this->id);
		Log_Logger::get()->debug("Reading url for sersor info: " . $url);
		$data = explode("\n", @file_get_contents($url));
		if(count($data) > 2) {
			$tmp = array();
			foreach($data as $line) {
				foreach(explode(" ", substr($line, 27)) as $tmp1) {
					$tmp2 = explode("=", $tmp1, 2);
					if(count($tmp2) == 2) {
						$tmp[trim($tmp2[0])] = trim($tmp2[1]);
					}
				}
			}
			$res = $tmp['t'] / 1000;
		}
		return $res;
	}
}

?>
